package com.flower.service.impl;

import com.flower.mapper.PutMapper;
import com.flower.model.entity.Put;
import com.flower.model.entity.Putstorage;
import com.flower.service.IPutService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @author lm
 * @create 2022-03-26 15:23
 */
@Service
public class PutServiceImpl implements IPutService {

    @Autowired
    private PutMapper putMapper;

    @Override
    public Page<Putstorage> findPage(Page<Putstorage> page, String putId, String putOper, String startTime,
                                     String endTime) {
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        return putMapper.findPage(page, putId, putOper, startTime, endTime);

    }

    @Override
    public Double sumByToday() {
        return putMapper.sumByToday();
    }

    @Override
    public int saleValidate() {
        Integer Validate;

        Validate = putMapper.totalput();

        if (Validate == null)
            return 0;
        return Validate.intValue();
    }

    @Override
    public void saveOrUpdate(Put put) {
        if (put.getId() == 0) {
            putMapper.add(put);
        } else {
            putMapper.update(put);
        }
    }

    @Override
    public List<Put> list() {
        List<Put> list = putMapper.getAllList();
        return list;
    }

    @Override
    public void removeById(Integer id) {
        putMapper.delPutById(id);
    }

    @Override
    public void removeByIds(List<Integer> ids) {
        ids.forEach(id -> putMapper.delPutById(id));
    }
//    @Override
//    public Page<Putstorage> findPage(Page<Putstorage> page, String putId) {
//        return putMapper.findPage(page,putId);
//
//    }
}
